package work.huangxin.share.controller.admin;

import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import work.huangxin.share.domain.weather.CityAdcode;
import work.huangxin.share.service.CityAdcodeService;
import work.huangxin.share.util.status.BaseResponse;
import work.huangxin.share.util.status.CodeEnum;
import work.huangxin.share.util.status.ResponseData;

/**
 * @author 季台星
 * @Date 2023 04 21 21 58
 */
@RestController
@RequestMapping("/wx/admin/api/adminArticle")
public class AdminCityAdcodeController {
    @Autowired
    private CityAdcodeService cityAdcodeService;
    @PostMapping("/addCity")
    public BaseResponse saveCityAsAdcode(@RequestBody CityAdcode cityAdcode){
        if (Strings.isNullOrEmpty(cityAdcode.getName()) || null == cityAdcode.getCityCode()){
            return ResponseData.error(CodeEnum.BODY_NOT_MATCH);
        }
        int isSuccess = cityAdcodeService.insertAdcode(cityAdcode.getName(), cityAdcode.getCityCode());
        if (isSuccess <= 0){
            return ResponseData.error(CodeEnum.BODY_NOT_MATCH);
        }
        return ResponseData.success();
    }
}
